import { _decorator, Component, EventTouch, Label, Node, tween, UITransform, v3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('test')
export class test extends Component {
    @property(Label) private label: Label = null

    start() {
        this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this)
        this.node.on(Node.EventType.TOUCH_END, this.onTouchEnd, this)
    }

    update(deltaTime: number) {
        
    }

    onTouchStart(event: EventTouch) {
        const obj = {
            n: 0
        }
        // const label = this.label.getComponent(Label)
        tween(obj).to(3, { n: 100 },
            {
                onUpdate: (target: { n: number }, ratio: number) => {
                    this.label.string = obj.n.toFixed(1).toString()
                },
                easing: 'quadOut'
            }).start()

        // const uiPos = event.getUILocation()

        // const transform = this.node.getComponent(UITransform)
        // const nodePos = transform.convertToNodeSpaceAR(v3(uiPos.x, uiPos.y))
        // console.log(uiPos, nodePos)
        this.node.setScale(v3(1.1, 1.1, 1))
    }

    onTouchEnd(event: EventTouch) {
        
        this.scheduleOnce(() => {
            this.node.setScale(v3(1, 1, 1))
        }, 0.05)
    }

    onDestroy() {
        
    }
}


